const PHONEREG = /^1[3|4|5|6|7|8][0-9]{9}$/;
const IDNUMBERREG = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;

/**
 * @author Dom
 * @description: key 对应 regChecking 函数传递的type。
*/
const regExp = {
    phone: PHONEREG,
    ID: IDNUMBERREG
};

/**
 * @author Dom
 * @param params, type: object
 * state: { type: phone/ID, value: value }
 * type 验证类型,
 * value 验证的值。
 * @return: true/false
 * @description:
*/
const regChecking = params => {
    if(!(params instanceof Object)){
        console.log('arguments must be a object on regChecking handler');
        return false
    }
    let type = params.type;
    let value = params.value;
    if(!type) {
        console.log('type is required on regChecking handler');
        return false
    }
    return regExp[type].test(value)
};

module.exports = {
    regChecking
};